package com.sun.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sun.pojo.entity.Products;
import com.sun.mapper.ProductsMapper;
import com.sun.pojo.vo.ProductsDisplayVO;
import com.sun.service.ProductsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * (Products)表服务实现类
 *
 * @author makejava
 * @since 2024-10-23 09:22:00
 */
@Service
public class ProductsServiceImpl implements ProductsService {
    @Autowired
    ProductsMapper productsMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param productId 主键
     * @return 实例对象
     */
    @Override
    public ProductsDisplayVO queryById(Integer productId) {
        return productsMapper.queryById(productId);
    }

    /**
     * 分页查询
     *
     * @param products    筛选条件
     * @param pageNum 分页对象
     * @return 查询结果
     */
    @Override
    public PageInfo<ProductsDisplayVO> queryByPage(Products products, Integer pageNum) {
        PageHelper.startPage(pageNum,5);
        List<ProductsDisplayVO> list =  productsMapper.queryAllByLimit(products);
        PageInfo<ProductsDisplayVO> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    /**
     * 新增数据
     *
     * @param products 实例对象
     * @return 实例对象
     */
    @Override
    public int insert(Products products) {
        return productsMapper.insert(products);
    }

    /**
     * 修改数据
     *
     * @param products 实例对象
     * @return 实例对象
     */
    @Override
    public int update(Products products) {
        return productsMapper.update(products);
    }

    /**
     * 通过主键删除数据
     *
     * @param productId 主键
     * @return 是否成功
     */
    @Override
    public int deleteById(Integer productId) {
        return productsMapper.deleteById(productId);
    }

    @Override
    public String selectImageUrl(Integer productId) {
        return productsMapper.selectImageUrl(productId);
    }
}
